<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <h1>sessionStorage</h1>
    <button id='btn1'>保存数据</button>
    <button id='btn2'>获取数据</button>
    <button id='btn3'>删除数据</button>
    <button id='btn4'>清空数据</button>

    <script>
        const btn1 = document.getElementById('btn1');
        const btn2 = document.getElementById('btn2');
        const btn3 = document.getElementById('btn3');
        const btn4 = document.getElementById('btn4');

        btn1.onclick = function(){
            let person = {name:'lyx',age:24};
            sessionStorage.setItem('persion',JSON.stringify(person));
            sessionStorage.setItem('text','测试sessionStorage.setItem');
        }

        btn2.onclick = function(){
            console.log(JSON.parse(sessionStorage.getItem('persion')));
        }

        btn3.onclick = function(){
            sessionStorage.removeItem('text');
        }

        btn4.onclick = function(){
            sessionStorage.clear();
        }
    </script>
</body>
</html>